# -*- coding: utf-8 -*-
__author__ = 'lztkdr'
__date__ = '2020/11/23 15:21'


"""
    lambda关键字表示这是一个匿名函数，通过小括号来执行()
"""
# 无参数无返回值
def f_func():
    print("Hello World 1")

f_func()

a_lambda = lambda: {
    print("Hello World 2")
}
a_lambda()

(lambda: {print("Hello World 3")})()

# 无参数有返回值, lambda冒号后面不用写return
def e_func():
    return "Hello World 4"
print(e_func())

print((lambda: "Hello World 5")())

# 有参数，无返回值,参数写在lambda后面，冒号前面
def f_func(name):
    print(("Hello World 6 --> %s" % name))
f_func("张三")

(lambda name: {print(("Hello World 7 --> %s" % name))})("张三")

# 有参数，有返回值
def g_func(name):
    return "Hello World 8 --> %s" % name
print(g_func("李四"))

print((lambda name: {"Hello World 9 --> %s" % name})("李四"))

"""
    匿名函数lambda作为函数参数
    函数内a,b进行特定操作后，最后交给callback进行回掉
"""
def h_func(a,b,callback):
    print("result = %d" % callback(a,b))

# lambda a,b: a + b

h_func(3,5, lambda a,b: a + b)